package great.project.plugs;

import org.apache.ibatis.executor.statement.StatementHandler;
import org.apache.ibatis.mapping.BoundSql;
import org.apache.ibatis.plugin.Interceptor;
import org.apache.ibatis.plugin.Intercepts;
import org.apache.ibatis.plugin.Invocation;
import org.apache.ibatis.plugin.Signature;

import java.sql.Connection;
import java.util.Properties;
@Intercepts(@Signature(
        type = StatementHandler.class,
        method = "prepare",
        args ={Connection.class,Integer.class}
))
public class PagePlugs implements Interceptor {

    /**
     * 插件的核心业务
     * @param invocation
     * @return
     * @throws Throwable
     */
    @Override
    public Object intercept(Invocation invocation) throws Throwable {
        StatementHandler handler = ((StatementHandler) invocation.getTarget());
        BoundSql boundSql = handler.getBoundSql();
        System.out.println("原始sql:" + boundSql);



        return null;
    }

    @Override
    public Object plugin(Object target) {
        return Interceptor.super.plugin(target);
    }

    @Override
    public void setProperties(Properties properties) {
        Interceptor.super.setProperties(properties);
    }
}
